# Fibonacci数列生成器定义
def fibonacci(n):
    a, b = 0, 1
    while True:
        if counter > n:
            break
        yield a  # 使用yield关键字生成下一个值
        a, b = b, a + b

# 生成并打印前10个斐波那契数字
f = fibonacci(10)
data = []
while True:
    try:
        data.append(next(f))
    except StopIteration:
        break
print(data)  # 输出：[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

# 注意：type(f)会返回<class 'generator'>，表明f是一个生成器对象
print(type(f))  # <class 'generator'>12